package com.android.flickr;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/*
 * allows the user to add a mini auth token.  When enter is pressed,
 * the key is returned in a bundle
 */
public class NoKey extends Activity {
	
	private flickrTalkr ft = new flickrTalkr();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.no_key);
        
        //create button object from enter button on screen and add listener
        Button enterButton = (Button) findViewById(R.id.button_enterKey);
        enterButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	
            	Bundle bundle = new Bundle();
            	//return bundle and finish activity
            	Intent mIntent = new Intent();
            	bundle.putString(FlickrPickr.KEY_TOKEN,ft.getToken());
		    	mIntent.putExtras(bundle);
		    	setResult(RESULT_OK, mIntent);
		    	finish();
            }
        });
        
        //create button object from authenticate button on screen and add listener
        //user will hit back button on the device to return to the flickr pickr app screen
        Button webButton = (Button) findViewById(R.id.button_key_website);
        webButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	ft.getFrob();
            	String url = FlickrPickr.USER_AUTH_URL+ft.authURL();
            	System.out.println("FIND URL "+url);
            	Uri uri = Uri.parse(url);
				NoKey.this.startActivity(new Intent(Intent.ACTION_VIEW, uri));
				
            }
        });
        
	}
}